using Game.Main.Model;
using UnityEngine;

namespace Game.Component
{
	public class WaterItem : BaseItem
	{
		private float waterLevel;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
			if (platforms != null)
			{
				waterLevel = data.y + platforms[0].Find("Area").GetComponent<BoxCollider2D>().bounds.max.y;
			}
			else
			{
				Trace.LogError("水面未配置放置区域" + base.itemData.id);
			}
			PlayDragSound();
		}

		public float GetCheckPlaceY()
		{
			if (platforms != null && platforms.Count > 0)
			{
				Transform transform = platforms[0].Find("Area");
				if (transform != null)
				{
					return transform.position.y;
				}
			}
			return float.MinValue;
		}

		public override bool AttachItem(BaseItem item, DepthType depthType, AttachType attachType, bool updatePosition)
		{
			bool flag = base.AttachItem(item, depthType, attachType, updatePosition);
			if (flag)
			{
				if (item.itemData.floatType == 0)
				{
					item.InWater(true, item.waterHeight);
				}
				else if (item.itemData.floatType == 2)
				{
					item.InWater(true, item.waterHeight);
				}
				else
				{
					item.InWater(true, waterLevel);
				}
			}
			return flag;
		}
	}
}
